<template>
	<view class="container">
		<text>用户档案</text>
		<button type="primary" @click="doLogout" plain="">退出按钮</button>
	</view>
</template>

<script>
	import {
		userGetBasic,
		userLogout
	} from '../../service';
	export default {
		name: "xzUserProfile",
		data() {
			return {
				userInfo: {}, //当前登录用户的信息
			};
		},
		methods: {
			//退出登录
			async doLogout() {
				//调用服务器端的接口:清除当前用户的登录痕迹
				let {
					code,
					msg
				} = await userLogout()
				if (code === 200) {
					//清除之前的登录痕迹
					uni.removeStorageSync('userToken')
					this.$emit('showChild', {
						childName: 'login'
					})
				}else{
					//弹出模态对话框,提示失败原因
					uni.showTabBar({
						icon: 'error',
						title: '退出失败',
						duration: 3000
					})
				}
			}
		},
		//生命周期方法 -- 组件(不是页面)挂载时
		async mounted() {
			uni.setNavigationBarTitle({
				title: '用户档案'
			})
			let data = await userGetBasic()
			this.userInfo = data
		}
	}
</script>

<style lang="scss">
	.container {
		position: absolute;
		width: 100%;
	}
</style>
